package com.example.controller;

import com.example.constant.ResultCodeConstant;
import com.example.dos.AwardDO;
import com.example.dto.AwardDTO;
import com.example.dto.AwardExportDTO;
import com.example.dto.AwardImportDTO;
import com.example.dto.FileUploadDTO;
import com.example.response.RestResult;
import com.example.service.AwardService;
import com.example.validation.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.groups.Default;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   获奖信息控制器
 * </p>
 * @author 34448
 */
@Api("获奖信息管理")
@RequestMapping("award")
@RestController
public class AwardController {

    @Autowired
    private AwardService awardService;

    /**
     * 新增获奖信息
     *
     * @param awardDTO 获奖信息
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增获奖信息")
    public RestResult<Boolean> addAward(@RequestBody @Validated(Default.class) AwardDTO awardDTO) {
        Boolean result = awardService.addAward(awardDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除获奖信息
     *
     * @param awardId 奖项ID
     * @return
     */
    @DeleteMapping("/delete/{awardId}")
    @ApiOperation("删除获奖信息")
    public RestResult<Boolean> deleteAward(@PathVariable @NotNull Integer awardId) {
        Boolean result = awardService.deleteAward(awardId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 修改获奖信息
     *
     * @param awardDTO 获奖信息
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改获奖信息")
    public RestResult<Boolean> updateAward(@RequestBody @Validated(AwardDTO.UpdateGroup.class) AwardDTO awardDTO) {
        Boolean result = awardService.updateAward(awardDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询获奖信息
     *
     * @param awardId 奖项ID
     * @return
     */
    @GetMapping("/info")
    @ApiOperation("查询获奖信息")
    public RestResult<List<AwardDO>> getAwards(@RequestParam(required = false) Integer awardId) {
        List<AwardDO> result = awardService.getAwards(awardId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 导入获奖信息
     *
     * @param awardImportDTO 导入获奖信息
     * @return
     */
    @PostMapping("/import")
    @ApiOperation("导入获奖信息")
    public RestResult<Boolean> importAwards(@RequestBody @Validated Default.class AwardImportDTO awardImportDTO) {
        Boolean result = awardService.importAwards(awardImportDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 导出获奖信息
     *
     * @param awardExportDTO 导出获奖信息
     * @return
     */
    @PostMapping("/export")
    @ApiOperation("导出获奖信息")
    public RestResult<Boolean> exportAwards(@RequestBody @Validated Default.class AwardExportDTO awardExportDTO) {
        Boolean result = awardService.exportAwards(awardExportDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 上传证书文件
     *
     * @param fileUploadDTO 文件上传信息
     * @return
     */
    @PostMapping("/upload-certificate")
    @ApiOperation("上传证书文件")
    public RestResult<Boolean> uploadCertificate(@RequestBody @Validated Default.class FileUploadDTO fileUploadDTO) {
        // Here you can implement the actual file upload logic
        // For now, we assume the file path is already provided and valid
        Boolean result = true; // Placeholder for actual file upload logic
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}